<template>
	<div class="allcontainer" v-loading="loading">
		<div class="h2">{{myInfo.ScoreName}}，当前{{myInfo.ScoreName}}{{ score.toFixed(2) }}</div>
		<div class="table" v-for="(item,i) in data" :key="i">
			<h2>{{ item.TypeName }} - 共{{ item.TotalScore }}分</h2>
			<el-table stripe ref="singleTable" :data="data[i].children.filter((m,n)=>n<item.ShowNum)"
				highlight-current-row style="width: 100%">
				<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
				<el-table-column prop="TypeName" label="活动分类" min-width="100" fixed="left" align="center"></el-table-column>
				<el-table-column prop="Title" label="标题" min-width="100"></el-table-column>
				<el-table-column prop="Score" :label="myInfo.ScoreName" min-width="100" align="right"></el-table-column>
				<el-table-column prop="AddTime" label="获得时间" min-width="100" align="center">
					<template slot-scope="scope">
						{{ scope.row.AddTime }}
					</template>
				</el-table-column>
			</el-table>
			<div class="seemore" @click="seeMore(item,i)">
				{{ item.ShowNum==999999?'收起':`查看更多共（${data[i].children.length}）条>>` }}
			</div>
		</div>
		<add :time="time" :type="loadingtype" v-if="addIf" @closeFun="closeFun"></add>
		<update :text="updatetext" v-if="updateIf" :time="time" @closeFun="closeFun"></update>
		<detail :text="detailtext" v-if="detailIf" :time="time" @closeFun="closeFun"></detail>
	</div>
</template>

<script>
	import Func from '@/utils/func';
	import Cache from '@/utils/cache'
	import {
		UserDoGetScoreList,
		DoDeleteUserApplyItem,
		DoSubmitUserApplyItem,
	} from '@/api/follow';
	import add from './addCredit'
	import update from './UpdateCredit.vue'
	import detail from './UserCreditApplyDetail.vue'
	const data = [];
	export default {
		components: {
			add,
			update,
			detail
		},
		data() {
			return {
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				loadingtype: 0,
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				detailtext: {},
				codeID: '',
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				TypeList: [],
				tableHeight: parseFloat(window.innerHeight - 160),
				TypeIDList: [],
				DepartCodeList: [],
				ProjectIDList: [],
				ishaveid: true,
				selectList: {},
				showModal: false,
				UserInfo: Cache.get('myInfo'),
				myInfo: Cache.get('myInfo'),
				ChairmanNo: this.$route.query.ChairmanNo,
				linktype: 1,
				ID: this.$route.query.ID,
				visible: false,
				deletelist: {},
				time: '',
				codeIf: false,
				detailIf: false,
				updateIf: false,
				updatetext: {}
			};
		},
		computed: {
			score: function() {
				let scoreList = this.data;
				let scoreAll = 0;
				for (let i = 0; i < scoreList.length; i++) {
					if (scoreList[i].TotalScore) {
						scoreAll = scoreAll + scoreList[i].TotalScore;
					}
				}
				return scoreAll;
			}
		},
		created() {
			this.getList();
			// this.getOtherList()
		},
		mounted() {},
		methods: {
			seeMore(item, i) {
				console.log(this.data[i].ShowNum)
				if (this.data[i].ShowNum == 999999) {
					this.data[i].ShowNum = 5
				} else {
					this.data[i].ShowNum = 999999
				}
			},
			sumbitapply(text) {
				let that = this
				this.$confirm({
					title: '提示',
					content: `您确定提交审批吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {}
						data.id = text.ID
						let res = await DoSubmitUserApplyItem(data);
						if (res.data.code == 0) {
							that.$message.success(res.data.msg)
							that.getList()
						} else {
							that.$message.error(res.data.msg)
						}
					}
				})
			},
			handleCancel(e) {
				this.visible = false
				this.getList()
			},
			deletemember(text) {
				// this.visible = true
				// this.deletelist = text
				let that = this
				this.$confirm({
					title: '提示',
					content: `您确定删除此条记录吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {}
						data.id = text.ID
						let res = await DoDeleteUserApplyItem(data);
						if (res.data.code == 0) {
							that.getList()
							that.$message.success(res.data.msg)
						} else {

							that.$message.error(res.data.msg)
						}
					}
				})
			},
			update(text) {
				this.updatetext = text
				this.time = new Date()
				this.updateIf = true
			},
			look(text) {
				this.detailtext = text
				this.time = new Date()
				this.detailIf = true
			},
			handleChange(val) {
				this.currentRow = val;
				if (val.ID) {
					this.ishaveid = false
					this.selectList = val
				} else {
					this.ishaveid = true
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				let res = await UserDoGetScoreList(data);
				this.loading = false;
				this.data = res.data.data;
				// const pagination = { ...this.pagination
				// };
				// pagination.total = res.data.pageInfo.TotalItemCount;
				// this.pagination = pagination;
			},
			async getOtherList() {
				let res = await GetUserApplyItemStateList()
				this.TypeList = res.data.data
			},
			addList() {
				this.loadingtype = 1
				this.time = new Date()
				this.addIf = !this.addIf;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			closeFun(index) {
				this.showModal = false
				this.addIf = false
				this.detailIf = false
				this.updateIf = false
				this.getList()
			},
		}
	};
</script>

<style lang="less" scoped>
	.table {
		margin-bottom: 20px;
		background: #fff;
		border-radius: 10px;
		padding: 15px;
		h2 {
			padding: 10px;
			line-height: 1.4;
			font-size: 14px;
			background-color: #eee;
			color: #000;
		}

		.seemore {
			text-align: center;
			padding: 10px 0;
			color: #0066FF;
			cursor: pointer;
		}
	}

</style>
